package com.itheima.mapdemo1;

import java.util.HashMap;
import java.util.Map;

public class MapDemo2 {
    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();

        map.put("itheima001", "小智");
        map.put("itheima002", "小美");
        map.put("itheima003", "大胖");
        map.put("itheima004", "小黑");
        map.put("itheima005", "大师");

//        method1(map);
//        method2(map);
//        method3(map);
//        method4(map);
//        method5(map);
//        method6(map);
//        method7(map);
    }

    private static void method7(Map<String, String> map) {
        int size = map.size();
        System.out.println(size);
    }

    private static void method6(Map<String, String> map) {
        boolean empty = map.isEmpty();
        System.out.println(empty);
        map.clear();
        boolean empty2 = map.isEmpty();
        System.out.println(empty2);
    }

    private static void method5(Map<String, String> map) {
        boolean result1 = map.containsValue("小智");
        boolean result2 = map.containsValue("AAA");
        System.out.println(result1);
        System.out.println(result2);
    }

    private static void method4(Map<String, String> map) {
        boolean result1 = map.containsKey("itheima001");
        boolean result2 = map.containsKey("itheima006");
        System.out.println(result1);
        System.out.println(result2);
    }

    private static void method3(Map<String, String> map) {
        map.clear();
        System.out.println(map);
    }

    private static void method2(Map<String, String> map) {
        String s = map.remove("itheima001");
        System.out.println(s);
        System.out.println(map);
    }

    private static void method1(Map<String, String> map) {
        // 如果添加的键是存在的，那么会覆盖原值，并将原值返回
        String s = map.put("itheima001", "AAA");
        System.out.println(s);
        System.out.println(map);
    }
}
